﻿using System;
using System.IO;
using System.Web;
using Ymca.Entities;
using Ymca.Web.Services.Interfaces;

namespace Ymca.Web.Services
{
    public class AttachmentBuilder: IAttachmentBuilder
    {
        private readonly string _uploadsFolder = "~/Uploads";

        public GalleryItem Create(HttpPostedFileBase file)
        {
			GalleryItem attachment = new GalleryItem();
			attachment.Name = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
			attachment.Url = Path.Combine(HttpContext.Current.Server.MapPath(_uploadsFolder), attachment.Name);
			attachment.Title = file.FileName;
			attachment.UploadDate = DateTime.Now;

            return attachment;
        }
    }
}